package com.hotel.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hotel.common.lang.Result;
import com.hotel.entity.Customer;
import com.hotel.entity.Floor;
import com.hotel.service.CustomerService;
import com.hotel.service.FloorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 关注公众号：MarkerHub
 * @since 2020-10-19
 */
@RestController
@RequestMapping("/floor")
public class FloorController {
    @Autowired
    FloorService floorService;

    //分页处理
    @GetMapping("/floorPage")
    public Result list(@RequestParam(defaultValue = "1") Integer currentPage) {

        Page page = new Page(currentPage, 5);
        IPage pageData = floorService.page(page, new QueryWrapper<Floor>().orderByDesc("id"));

        return Result.succ(pageData);
    }

    //查询用户
    @GetMapping("/floor/{id}")
    public Result detail(@PathVariable(name = "id") Long id) {
        Floor floor = floorService.getById(id);
        Assert.notNull(floor, "已删除！");
        return Result.succ(floor);
    }


    @PostMapping("/floor/edit")
    public Result edit(@Validated @RequestBody Floor floor) {
        System.err.println(floor.toString());
        floorService.saveOrUpdate(floor);
        return Result.succ("操作成功");
    }

}
